%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Reproducing Table 3 of the paper:
%Reis, Ricardo (2006) "Inattentive Producers," Review of Economic Studies.
%Written by: Ricardo Reis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This program produces the MA representations for the shocks
% Uses AR(1) for g_m and white hoise for g_a, according with data
% Needs: alpha, lambda, upper, par1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%STEP 1: INPUT THE MA REPRESENTATION FOR DRIVING SHOCKS
%Ar(1) Nominal income: g_m = par1*L.g_ + epsilon
rho(1,1)=1;
for j=1:upper+1
    rho(j+1,1)=par1^j;
end
%White noise for technology growth
eta(1,1)=1;
for j=1:upper+1
    eta(j+1,1)=0;
end
%useful sums
sum_lambda(1,1)=1;
sum_rho(1,1)=rho(1,1);
sum_eta(1,1)=eta(1,1);
for j=1:upper+1
    sum_lambda(j+1,1)=sum_lambda(j,1)+(1-lambda)^j;
    sum_rho(j+1,1)=sum_rho(j,1)+rho(j+1,1);
    sum_eta(j+1,1)=sum_eta(j,1)+eta(j+1,1);
end
   
%STEP 2: SOLVE FOR INFLATION
%gamma is on m shocks, whereas csi is on tech shocks
gamma(1,1)=alpha*lambda/(1-lambda*(1-alpha));
sum_gamma(1,1)=gamma(1,1);
csi(1,1)=alpha*lambda/(1-lambda*(1-alpha));
sum_csi(1,1)=csi(1,1);
for j=1:upper
    temp1=1-lambda*(1-alpha)*sum_lambda(j+1,1);
    %m part
    temp2=-sum_gamma(j,1)+sum_rho(j+1,1)+rho(j+1,1)*(sum_lambda(j+1,1)-1);
    gamma(j+1,1)=alpha*lambda*temp2/temp1;
    sum_gamma(j+1,1)=sum_gamma(j,1)+gamma(j+1,1);
    %tech part
    temp3=-sum_csi(j,1)+sum_eta(j+1,1)+eta(j+1,1)*(sum_lambda(j+1,1)-1);
    csi(j+1,1)=alpha*lambda*temp3/temp1;
    sum_csi(j+1,1)=sum_csi(j,1)+csi(j+1,1);
end
csi=-csi;
sum_csi=-sum_csi;

clear j temp1 temp2 temp3 sum_gamma sum_csi sum_lambda sum_rho sum_eta